package logic

import (
	"context"
	"fmt"

	"MBTI/model"
	"MBTI/rpc/student/internal/svc"
	"MBTI/rpc/student/stu"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddStudentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddStudentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddStudentLogic {
	return &AddStudentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddStudentLogic) AddStudent(in *stu.AddStuReq) (*stu.AddSuccessResp, error) {
	// todo: add your logic here and delete this line
	id, er := l.svcCtx.StudentModel.FindforID(in.StudentNo)
	if er != nil {
		return nil, er
	}
	fmt.Println(er)
	ifAddSuc, err := l.svcCtx.ResultModel.AddResult(&model.Result{
		StudentID: id,
		StudentNo: in.StudentNo,
		MBTI:      in.MBTI,
		Answer:    in.Answer,
	})
	fmt.Println(err)
	if err != nil {
		return nil, err
	}

	return &stu.AddSuccessResp{IsSuccess: ifAddSuc}, nil
}
